/*
 * @Description: LocalStorage临时缓存
 * @Author: HuiSir<273250950@qq.com>
 * @Date: 2021-09-07 17:29:01
 * @LastEditTime: 2025-08-11 18:36:30
 */

/* eslint-disable */
import { StorageItem } from "@/init/types";

export default class LocalCache {
  /**
   * 获取缓存
   */
  static getCache(item: StorageItem): any | null {
    return JSON.parse(
      (window as any)[item.type].getItem(item.key) || '{"value":null}'
    ).value;
  }

  /**
   * 设置缓存
   */
  static setCache(
    item: StorageItem,
    value: string | object | number | boolean | any[] | null
  ) {
    (window as any)[item.type].setItem(item.key, JSON.stringify({ value }));
  }

  /**
   * 移除缓存
   */
  static removeCache(item: StorageItem) {
    (window as any)[item.type].removeItem(item.key);
  }
}
